import $API from '@/api/services'

const aerial = {
  state: {
    aerialData: null,
    aearialLoadInfo: null,
    aerialGroupSceneList: null,
    aerialSceneId: 0,
  },
  actions: {
    initAearialData({ commit }, obj) {
      $API('getPanoInfo', [obj.panoId]).then(res => {
        if (res.code == 100) {
          console.log(res)
          // 动画数据
          let infoLoad = null
          if (res.data.load_type == 1) {
            infoLoad = {
              fk_userpano_load_id: res.data.fk_userpano_load_id,
              load_type: res.data.load_type,
            }
          } else {
            if (res.data.loadinfo) {
              infoLoad = res.data.loadinfo
              infoLoad.load_type = res.data.load_type
              infoLoad.fk_userpano_load_id = res.data.fk_userpano_load_id
            }
            
          }
          this.dispatch('fetchOverviewLoadInfo', infoLoad)
          // 过滤场景分组列表
          if (res.data.group_scene_list) {
            let filterArr = res.data.group_scene_list.filter(item => (item.scenelist && item.scenelist.length > 0))
            console.log(filterArr)
            commit('SAVE_GROUP_LIST', filterArr)
          }
          // 赋值航拍场景id
          if (res.data.scene_aerial_list && res.data.scene_aerial_list.length > 0) {
            res.data.scene_aerial_list.map(item => {
              if (item.is_aerial) {
                console.log(item.scene_id)
                commit('AERIAL_SCENE_ID', item.scene_id)
              }
            })
          }
          commit('SAVE_AERIAL_DATA', res.data)
        }
      })
    }
  },
  mutations: {
    // 航拍场景id
    AERIAL_SCENE_ID: (state, id) => {
      state.aerialSceneId = id
    },
    // 作品信息
    SAVE_AERIAL_DATA: (state, data) => {
      state.aerialData = data
    },
    // 场景列表
    SAVE_GROUP_LIST: (state, data) => {
      state.aerialGroupSceneList = data
    }
  }
}

export default aerial
